package cn.kmsoft.stgeometry.landm;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author : cqwensten
 * @description : todo
 * @email : cqwensten@163.com
 * @date : 2023/2/9
 */
public class StgeoFeature2 implements Serializable,Comparable{
    private static final long serialVersionUID = 1L;
    private String uuid;
    private String ffid;
    private int order;
    private String geomWkt;
    private Map<String,Object> properties;
    private String layerFlag;

    public StgeoFeature2() {
        this.uuid = UUID.randomUUID().toString();
        this.ffid = UUID.randomUUID().toString();
        this.properties = new HashMap<String,Object>();
    }
    public StgeoFeature2(int order) {
        this.uuid = UUID.randomUUID().toString();
        this.ffid = UUID.randomUUID().toString();
        this.order = order;
        this.properties = new HashMap<String,Object>();
    }


    public String getUuid() {
        return uuid;
    }
    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getFfid() {
        return ffid;
    }
    public void setFfid(String ffid) {
        this.ffid = ffid;
    }


    public String getLayerFlag() {
        return layerFlag;
    }
    public void setLayerFlag(String layerFlag) {
        this.layerFlag = layerFlag;
    }
    public int getOrder() {
        return order;
    }
    public void setOrder(int order) {
        this.order = order;
    }

    public String getGeomWkt() {
        return geomWkt;
    }
    public void setGeomWkt(String geomWkt) {
        this.geomWkt = geomWkt;
    }

    public Map<String, Object> getProperties() {
        return properties;
    }
    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }
    @Override
    public int compareTo(Object o) {
        StgeoFeature2 sta2 = (StgeoFeature2)o;
        int ord= this.order-sta2.getOrder();
        if( ord ==0 ) {
            return compare(this.uuid, sta2.getUuid());
        }
        return ord;
    }
    public int compare(String o1, String o2) {
        return o2.compareTo(o1);
    }

    @Override
    public int hashCode() {
        int hashCode = this.uuid.hashCode();
        hashCode = 17*hashCode + this.ffid.hashCode();
        return hashCode;
    }

    @Override
    public boolean equals(Object obj) {
        if( !(obj instanceof StgeoFeature2)) {
            return false;
        }

        //地址相等
        StgeoFeature2 stgeoFea = (StgeoFeature2) obj;
        //if (this == stgeoFea) {
        //return true;
        //}
        //根据UUID进行判断
        if (stgeoFea.uuid.equals(this.uuid) && stgeoFea.getFfid().equals(this.ffid)) {
            return true;
        } else {
            return false;
        }
    }
}
